﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using DAL;

namespace WcfService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
   
    public class AssistantAssistantService : IAssistantService
    {
        private static string _connectionString = WcfService.Properties.Settings.Default.connectionString;  
 
        public IList<Trip> GetTrips(User user)
        {
            using (var ctx = new TripAssistantDMContainer(_connectionString))
            {
                var trips = from t in ctx.Trips select t;
                return trips.ToList(); 
            }
        }

        public IList<User> GetUsers()
        {

            using (var ctx = new TripAssistantDMContainer(_connectionString))
            {
                //var users =
                //    ctx.Users.Select(
                //        x => new User() {Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, Email = x.Email});

                var users = from u in ctx.Users select u;  
                return users.ToList(); 
            }
        }

        public IList<Order> GetOrders(Trip trip)
        {
            using (var ctx = new TripAssistantDMContainer(_connectionString))
            {
                var orders = from o in ctx.Orders
                             where o.TripId == trip.Id
                             select o;
                return orders.ToList(); 

            }
        }

        public int GetIntValue()
        {
            return 101; 
        }
    }
}
